﻿using IOA.MES.Client.Common;
using System;
using System.Collections.Generic;
using System.Windows;

namespace IOA.MES.Client.Laminator
{
    /// <summary>
    /// WinLaminatorPrinterSetting.xaml 的交互逻辑
    /// </summary>
    public partial class WinLaminatorPrinterSetting : Window
    {
        public WinLaminatorPrinterSetting()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var barCodePrinter = BaseEnv.GetStorage("叠层条码") ?? string.Empty;
            var barCodeCount = Convert.ToInt32(BaseEnv.GetStorage("叠层条码数量") ?? "0");

            var printers = new Seagull.BarTender.Print.Printers();
            var dataSource = new List<string> { "" };
            foreach (Seagull.BarTender.Print.Printer printer in printers)
            {
                dataSource.Add(printer.PrinterName);
            }
            cbPrinter.ItemsSource = dataSource;
            cbPrinter.SelectedIndex = dataSource.IndexOf(barCodePrinter);

            var countSource = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            cbCount.ItemsSource = countSource;
            cbCount.SelectedIndex = barCodeCount;
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var barCodePrinter = Convert.ToString(cbPrinter.SelectedValue);
            var barCodeCount = Convert.ToString(cbCount.SelectedValue);
            BaseEnv.SetStorage("叠层条码", barCodePrinter);
            BaseEnv.SetStorage("叠层条码数量", barCodeCount);
            DialogResult = true;
            Close();
        }
    }
}
